﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MockPrjTeam2.Entity;
using MockPrjTeam2.Biz;

namespace MockPrjTeam2.Pages.Forms
{
    public partial class Programme1 : System.Web.UI.Page
    {
        static bool dd = false;
        protected void Page_Load(object sender, EventArgs e)
        {
            string insert = this.Page.Request.QueryString["insert"];
            if (!IsPostBack)
            {
                if (insert == "a")
                {
                    dd = true;
                    string strA = this.Page.Request.QueryString["ID"];
                    lblid.Text = this.Page.Request.QueryString["ID"];
                    List<Entity.ProgrammesInfor> lst = new List<Entity.ProgrammesInfor>();
                    lst = ProgrammesBIZ.Programme_Getby_Id(strA);
                    if (lst.Count > 0)
                    {
                        txtProgrammeName.Text = lst[0].ProgrammeName;
                        txtDescription.Text = lst[0].Description;
                        txtContact.Text = lst[0].Contact;
                    }
                }

                else
                {
                    dd = false;
                    txtProgrammeName.Text = "";
                    txtDescription.Text = "";
                    txtContact.Text = "";
                }
            }
        }

        protected void LinkButton10_Click(object sender, EventArgs e)
        {
            //string Name = txtProgrammeName.Text;
            //List<Entity.ProgrammesInfor> lst = new List<Entity.ProgrammesInfor>();
            //lst = ProgrammesBIZ.Sp_Programme_GetName(Name);
            //if (lst.Count > 0)
            //{
            //    Label1.Text = "Trung ten ProgrammeName";
            //    txtProgrammeName.Text = "";
            //}
            //else
            //{
                Entity.ProgrammesInfor obj = new Entity.ProgrammesInfor();
                obj.ProgrammeID = lblid.Text;
                obj.ProgrammeName = txtProgrammeName.Text;
                obj.Description = txtDescription.Text;
                obj.ContactID = txtContact.Text;
                if (dd == true)
                {

                    ProgrammesBIZ.Programmes_update(obj);
                    Response.Redirect("~/Pages/Views/Programme.aspx");
                }
                else
                {
                    string Name = txtProgrammeName.Text;
                    List<Entity.ProgrammesInfor> lst = new List<Entity.ProgrammesInfor>();
                    lst = ProgrammesBIZ.Sp_Programme_GetName(Name);
                    if (lst.Count > 0)
                    {
                        Label1.Text = "Trung ten ProgrammeName";
                        txtProgrammeName.Text = "";
                    }
                    else
                    {
                        ProgrammesBIZ.Programmes_insert(obj);
                        Response.Redirect("~/Pages/Views/Programme.aspx");
                    }
                }
        }
    }
}